package control;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.DefaultListModel;
import javax.swing.JList;

import dao.AbstractTable;

public class SwitchClickListListener<T extends AbstractTable> implements
	MouseListener {

    private DefaultListModel<T> listOut = null;
    private DefaultListModel<T> listIn = null;

    public SwitchClickListListener(DefaultListModel<T> listOut,
	    DefaultListModel<T> listIn) {
	this.listOut = listOut;
	this.listIn = listIn;
    }

    @Override
    public void mouseReleased(MouseEvent me) {
	if (me.getClickCount() > 1)
	    this.switcher(((JList<?>) me.getSource()).getSelectedIndex());
    }

    @Override
    public void mouseClicked(MouseEvent me) {
    }

    private void switcher(int indice) {
	T instd = listOut.get(indice);

	if (indice >= 0) {
	    listIn.addElement(instd);
	    listOut.remove(indice);
	}
    }

    @Override
    public void mouseEntered(MouseEvent arg0) {
    }

    @Override
    public void mouseExited(MouseEvent arg0) {
    }

    @Override
    public void mousePressed(MouseEvent arg0) {
    }
}
